package org.jugile.proto2.common;

import org.jugile.util.Jugile;



/**
 * BookType  
 */
public class FamilyType implements java.io.Serializable, Comparable, org.jugile.util.EnumType {
	// types
	/**
	 * 
	 */
	public final static FamilyType SMALL = new FamilyType(1, "SMALL");  
	/**
	 * 
	 */
	public final static FamilyType BIG = new FamilyType(2, "BIG");  

	/**
	 * Vain domainin sis?iseen k?ytt??n tarkoitettu metodi. 
	 * Tarvitaan mapattaessa persistenssikerrokseen ja takaisin.
	 * @param v
	 * @return
	 */
	public static FamilyType map(int v) {
		if (v == 1) return SMALL;
		if (v == 2) return BIG;
		return null;
	}
	
	public static FamilyType map(Integer v) {
		if (v == null) return null;
		return map(v.intValue());
	}

	public static FamilyType map(String v) {
		return map(Jugile.parseIntSafe(v));
	}

	private int value;
	private String label;

	private FamilyType(int value, String label) {
		this.value = value;
		this.label = label;
	}

	private final static FamilyType[] items = {
		FamilyType.SMALL,
		FamilyType.BIG,
	};
	public static FamilyType[] getItems() {
		return items;
	}
	
	public String toString() { return label; }
	public String getLabel() { return label; }
	public int getValue() { return value; }
	
	private Object readResolve() throws java.io.ObjectStreamException {
		return map(value); 
	}
	
	
	public int compareTo(Object other) {
		try {
			return compareTo ((FamilyType) other);
		} catch (ClassCastException ex) {
            return 1;
        }
	}
    public int compareTo(FamilyType other) {
        if (other == null) return 1;
        Integer oi = new Integer(other.value);
        Integer i = new Integer(this.value);
        return i.compareTo(oi);
    }


	
}